﻿using System.ServiceModel.Channels;
using System.ServiceModel.Description;

namespace XchangeStreamer.Core
{
    public static class MessageConverter<T> where T: class
    {
        #region Private Fields

        private static TypedMessageConverter converter;

        #endregion

        #region Const.

        static MessageConverter()
        {
            converter = TypedMessageConverter.Create(typeof(T), XchangeStreamer.Utilities.Settings.Action);
        }

        #endregion

        #region Public Methods

        public static System.ServiceModel.Channels.Message ToMessage(T message)
        {
            return converter.ToMessage(message);
        }

        public static T FromMessage(System.ServiceModel.Channels.Message message)
        {
            return converter.FromMessage(message) as T;
        }

        #endregion
    }
}
